package cn.wetcland.urban.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.wetcland.urban.admin.dto.ArticleAddDTO;
import cn.wetcland.urban.admin.dto.ArticleUpdateDTO;
import cn.wetcland.urban.admin.service.UtArticleService;
import cn.wetcland.urban.common.AjaxResponse;
import cn.wetcland.urban.generator.domain.UtArticle;
import cn.wetcland.urban.generator.dto.BaseConditionSearchDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Resource
    private UtArticleService articleService;

    @GetMapping("/articleList")
    public AjaxResponse articleList(BaseConditionSearchDTO searchDTO) {
        Page<UtArticle> articlePage = articleService.articleList(searchDTO);
        return AjaxResponse.success(articlePage);
    }

    @SaCheckLogin
    @PostMapping("/articleAdd")
    public AjaxResponse articleAdd(@RequestBody ArticleAddDTO addDTO) {
        articleService.articleAdd(addDTO);
        return AjaxResponse.success();
    }

    @SaCheckLogin
    @PutMapping("/articleUpdate")
    public AjaxResponse articleUpdate(@RequestBody ArticleUpdateDTO updateDTO) {
        articleService.articleUpdate(updateDTO);
        return AjaxResponse.success();
    }

    @DeleteMapping("/articleDelete/{articleId}")
    public AjaxResponse articleDelete(@PathVariable Long articleId) {
        articleService.articleDelete(articleId);
        return AjaxResponse.success();
    }
    
}
